package club.vann.kafka.mock.kafka;

import org.springframework.kafka.core.KafkaTemplate;

public class KafkaProducer {
  private final KafkaTemplate<String, byte[]> kafkaTemplate;

  /** kafka发送消息生产者 */
  private static KafkaProducer kafkaProducer;

  public KafkaProducer(KafkaTemplate<String, byte[]> kafkaTemplate) {
    this.kafkaTemplate = kafkaTemplate;
  }

  public static KafkaProducer init(KafkaTemplate<String, byte[]> kafkaTemplate) {
    KafkaProducer kafkaProducer = new KafkaProducer(kafkaTemplate);
    KafkaProducer.kafkaProducer = kafkaProducer;
    return kafkaProducer;
  }

  public void send(String topic, byte[] value) {
    this.kafkaTemplate.send(topic, value);
  }

  public void send(String topic, String key, byte[] value) {
    this.kafkaTemplate.send(topic, key, value);
  }
}
